package pl.umk.mat.fred.unicore.urc.storagemanagement.preferences;

import java.util.List;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

import pl.umk.mat.fred.unicore.urc.storagemanagement.StorageManagementActivator;
import pl.umk.mat.fred.unicore.urc.storagemanagement.analytics.TimeMeter;
import pl.umk.mat.fred.unicore.urc.storagemanagement.unicore.Storage;

/**
 * Class used to initialize default preference values.
 */
public class PreferenceInitializer extends AbstractPreferenceInitializer {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
	 */
	public void initializeDefaultPreferences() {
		IPreferenceStore store = StorageManagementActivator.getDefault().getPreferenceStore();
		
		List<Storage> storages = StorageManagementActivator.getDefault().getStorageList();
		for (Storage s : storages) {
			store.setDefault(PreferenceConstants.P_PRIORITY_PREFIX + s.getUrl(), 50);
		}
		
		store.setDefault(PreferenceConstants.P_TIMES_HISTORY_SIZE, 3);
		store.setDefault(PreferenceConstants.P_TEST_FILE_SIZE, 10);
		store.setDefault(PreferenceConstants.P_MEASURE_INTERVAL, 30);
		store.addPropertyChangeListener(new IPropertyChangeListener() {
			
			@Override
			public void propertyChange(PropertyChangeEvent event) {
				if (PreferenceConstants.P_TEST_FILE_SIZE.equals(event.getProperty())) {
					TimeMeter timeMeter = StorageManagementActivator.getDefault().getTimeMeter();
					timeMeter.fireTestFileSizeChanged();
				}
			}
		});
		
		store.setDefault(PreferenceConstants.P_RED_YELLOW_COLOR, 10);
		store.setDefault(PreferenceConstants.P_YELLOW_GREEN_COLOR, 100);
	}

}
